package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.IotDeviceEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.IotDeviceEntityMapper;
import com.hzhr.iot.device.entity.IotDeviceEntity;
import com.hzhr.iot.device.entity.ext.IotDeviceEntityExt;
import com.hzhr.iot.device.queryModel.custom.IotDeviceCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class IotDeviceDao {
    @Autowired
    IotDeviceEntityMapper iotDeviceEntityMapper;
    @Autowired
    IotDeviceEntityCustomMapper iotDeviceEntityCustomMapper;

    public int insert(IotDeviceEntity record) {
        if (record == null) return 0;
        int changeCount = iotDeviceEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = iotDeviceEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(IotDeviceEntity record) {
        if (record == null) return 0;
        int changeCount = iotDeviceEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = iotDeviceEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public IotDeviceEntityExt selectEntity(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<IotDeviceEntityExt> extList = iotDeviceEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<IotDeviceEntity> selectEntityList(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<IotDeviceEntityExt> extList = iotDeviceEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<IotDeviceEntity> entityList = new ArrayList<>();
        for (IotDeviceEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public IotDeviceEntityExt selectExt(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<IotDeviceEntityExt> extList = iotDeviceEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<IotDeviceEntityExt> selectExtList(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<IotDeviceEntityExt> extList = iotDeviceEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(IotDeviceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = iotDeviceEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
